package rs.graphics;

import rs.NodeSub;// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

public class DrawingArea extends NodeSub {

    public static void initDrawingArea(int i, int j, int ai[]) {
        pixels = ai;
        width = j;
        height = i;
        setDrawingArea(i, 0, j, 0);
    }

    public static void defaultDrawingAreaSize() {
        topX = 0;
        topY = 0;
        viewport_w = width;
        viewport_h = height;
        rwidth_o1 = viewport_w - 1;
        rwidth_mid = viewport_w / 2;
    }

    public static void setDrawingArea(int i, int j, int k, int l) {
        if (j < 0)
            j = 0;
        if (l < 0)
            l = 0;
        if (k > width)
            k = width;
        if (i > height)
            i = height;
        topX = j;
        topY = l;
        viewport_w = k;
        viewport_h = i;
        rwidth_o1 = viewport_w - 1;
        rwidth_mid = viewport_w / 2;
        rheight_mid = viewport_h / 2;
    }

    public static void setAllPixelsToZero() {
        int i = width * height;
        for (int j = 0; j < i; j++)
            pixels[j] = 0;

    }

    public static void method335(int i, int j, int k, int l, int i1, int k1) {
        if (k1 < topX) {
            k -= topX - k1;
            k1 = topX;
        }
        if (j < topY) {
            l -= topY - j;
            j = topY;
        }
        if (k1 + k > viewport_w)
            k = viewport_w - k1;
        if (j + l > viewport_h)
            l = viewport_h - j;
        int l1 = 256 - i1;
        int i2 = (i >> 16 & 0xff) * i1;
        int j2 = (i >> 8 & 0xff) * i1;
        int k2 = (i & 0xff) * i1;
        int k3 = width - k;
        int l3 = k1 + j * width;
        for (int i4 = 0; i4 < l; i4++) {
            for (int j4 = -k; j4 < 0; j4++) {
                int l2 = (pixels[l3] >> 16 & 0xff) * l1;
                int i3 = (pixels[l3] >> 8 & 0xff) * l1;
                int j3 = (pixels[l3] & 0xff) * l1;
                int k4 = ((i2 + l2 >> 8) << 16) + ((j2 + i3 >> 8) << 8) + (k2 + j3 >> 8);
                pixels[l3++] = k4;
            }

            l3 += k3;
        }
    }

    public static void method336(int i, int j, int k, int l, int i1) {
        if (k < topX) {
            i1 -= topX - k;
            k = topX;
        }
        if (j < topY) {
            i -= topY - j;
            j = topY;
        }
        if (k + i1 > viewport_w)
            i1 = viewport_w - k;
        if (j + i > viewport_h)
            i = viewport_h - j;
        int k1 = width - i1;
        int l1 = k + j * width;
        for (int i2 = -i; i2 < 0; i2++) {
            for (int j2 = -i1; j2 < 0; j2++)
                pixels[l1++] = l;

            l1 += k1;
        }

    }

    public static void fillPixels(int i, int j, int k, int l, int i1) {
        drawHLine(i1, l, j, i);
        drawHLine((i1 + k) - 1, l, j, i);
        method341(i1, l, k, i);
        method341(i1, l, k, (i + j) - 1);
    }

    public static void method338(int i, int j, int k, int l, int i1, int j1) {
        method340(l, i1, i, k, j1);
        method340(l, i1, (i + j) - 1, k, j1);
        if (j >= 3) {
            method342(l, j1, k, i + 1, j - 2);
            method342(l, (j1 + i1) - 1, k, i + 1, j - 2);
        }
    }

    public static void drawHLine(int i, int j, int k, int l) {
        if (i < topY || i >= viewport_h)
            return;
        if (l < topX) {
            k -= topX - l;
            l = topX;
        }
        if (l + k > viewport_w)
            k = viewport_w - l;
        int i1 = l + i * width;
        for (int j1 = 0; j1 < k; j1++)
            pixels[i1 + j1] = j;

    }

    private static void method340(int i, int j, int k, int l, int i1) {
        if (k < topY || k >= viewport_h)
            return;
        if (i1 < topX) {
            j -= topX - i1;
            i1 = topX;
        }
        if (i1 + j > viewport_w)
            j = viewport_w - i1;
        int j1 = 256 - l;
        int k1 = (i >> 16 & 0xff) * l;
        int l1 = (i >> 8 & 0xff) * l;
        int i2 = (i & 0xff) * l;
        int i3 = i1 + k * width;
        for (int j3 = 0; j3 < j; j3++) {
            int j2 = (pixels[i3] >> 16 & 0xff) * j1;
            int k2 = (pixels[i3] >> 8 & 0xff) * j1;
            int l2 = (pixels[i3] & 0xff) * j1;
            int k3 = ((k1 + j2 >> 8) << 16) + ((l1 + k2 >> 8) << 8) + (i2 + l2 >> 8);
            pixels[i3++] = k3;
        }

    }

    public static void method341(int i, int j, int k, int l) {
        if (l < topX || l >= viewport_w)
            return;
        if (i < topY) {
            k -= topY - i;
            i = topY;
        }
        if (i + k > viewport_h)
            k = viewport_h - i;
        int j1 = l + i * width;
        for (int k1 = 0; k1 < k; k1++)
            pixels[j1 + k1 * width] = j;

    }

    private static void method342(int i, int j, int k, int l, int i1) {
        if (j < topX || j >= viewport_w)
            return;
        if (l < topY) {
            i1 -= topY - l;
            l = topY;
        }
        if (l + i1 > viewport_h)
            i1 = viewport_h - l;
        int j1 = 256 - k;
        int k1 = (i >> 16 & 0xff) * k;
        int l1 = (i >> 8 & 0xff) * k;
        int i2 = (i & 0xff) * k;
        int i3 = j + l * width;
        for (int j3 = 0; j3 < i1; j3++) {
            int j2 = (pixels[i3] >> 16 & 0xff) * j1;
            int k2 = (pixels[i3] >> 8 & 0xff) * j1;
            int l2 = (pixels[i3] & 0xff) * j1;
            int k3 = ((k1 + j2 >> 8) << 16) + ((l1 + k2 >> 8) << 8) + (i2 + l2 >> 8);
            pixels[i3] = k3;
            i3 += width;
        }

    }

    public DrawingArea() {
    }

    public static int pixels[];
    public static int width;
    public static int height;
    public static int topY;
    public static int viewport_h;
    public static int topX;
    public static int viewport_w;
    public static int rwidth_o1;
    public static int rwidth_mid;
    public static int rheight_mid;

}
